<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>

<body>
    <div id="app">
        <cpn></cpn>
    </div>
    <template id="cpn">
        <div>
            <div>我是cpn组件</div>
            <ccpn></ccpn>
            <button @click="bclick">点击a</button>
        </div>
    </template>
    <template id="ccpn">
        <div>
            <div>我是ccpn组件</div>
            <button @click="ccpnClick">点击d</button>
        </div>
    </template>
    <script>
        //$parent 和 $root
        const app = new Vue({
            el: '#app',
            data: {
                msg: '我是父组件'
            },
            methods: {},
            components: {
                cpn: {
                    template: '#cpn',
                    data() {
                        return {
                            msg: 'cpn'
                        }
                    },
                    methods: {
                        bclick() {
                            // console.log('123')
                            console.log(this.$parent)
                            return undefined
                        }
                    },
                    components: {
                        ccpn: {
                            template: '#ccpn',
                            methods: {
                                ccpnClick() {
                                    // this.$parent.bclick()
                                    // console.log(this.$root.msg)
                                    console.log(this.$parent.$parent.msg)
                                }
                            }
                        }
                    }
                },
            }
        })
    </script>
</body>

</html>